﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Peekaboo2008.dao;
using Peekaboo2008.model;

namespace Peekaboo2008.view
{
    public partial class FormKhachHang : Form
    {
        public FormKhachHang()
        {
            InitializeComponent();
            FormKhachMuaHangLoad();
        }

        public void FormKhachMuaHangLoad()
        {
            DataTable dt = KhachHangDAO.KhachHangMuaHang_GetAll();
            dgvKhachMuahang.DataSource = dt;
        }

        private void dgvKhachMuahang_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            FormKhachHang formKhachHang = this;

            KhachHangModel khachHangModel = new KhachHangModel();
            khachHangModel.Id = dgvKhachMuahang.CurrentRow.Cells["Id"].Value.ToString();
            khachHangModel.MaKhuVuc = dgvKhachMuahang.CurrentRow.Cells["maKhuVuc"].Value.ToString();
            khachHangModel.MaNhomKhachHang = dgvKhachMuahang.CurrentRow.Cells["maNhomKhachHang"].Value.ToString();
            khachHangModel.MaSoThue = dgvKhachMuahang.CurrentRow.Cells["maSoThue"].Value.ToString();
            khachHangModel.NganHang = dgvKhachMuahang.CurrentRow.Cells["nganHang"].Value.ToString();
            khachHangModel.SoTaiKhoan = dgvKhachMuahang.CurrentRow.Cells["soTaiKhoan"].Value.ToString();
            khachHangModel.Tel = dgvKhachMuahang.CurrentRow.Cells["tel"].Value.ToString();
            khachHangModel.Ten = dgvKhachMuahang.CurrentRow.Cells["tenKH"].Value.ToString();
            khachHangModel.Fax = dgvKhachMuahang.CurrentRow.Cells["fax"].Value.ToString();
            khachHangModel.DiaChi = dgvKhachMuahang.CurrentRow.Cells["diaChi"].Value.ToString();
            khachHangModel.Email = dgvKhachMuahang.CurrentRow.Cells["email"].Value.ToString();
            khachHangModel.GhiChu = dgvKhachMuahang.CurrentRow.Cells["ghiChu"].Value.ToString();

            FormChiTietKhachHang formChiTietKhachHang = new FormChiTietKhachHang(khachHangModel, ref formKhachHang);
            formChiTietKhachHang.ShowDialog();
        }

        private void FormKhachHang_Load(object sender, EventArgs e)
        {
            this.KeyPreview = true;
            this.KeyDown += new System.Windows.Forms.KeyEventHandler(this.FormKhachHang_KeyDown);
        }

        private void FormKhachHang_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.F5)
            {
                tsbThem.PerformClick();
            }
            else if (e.KeyCode == Keys.F4)
            {
                tsbThoat.PerformClick();
            }
        }

        private void tsbThem_Click(object sender, EventArgs e)
        {
            FormKhachHang formKhachHang = this;
            FormChiTietKhachHang formChiTietKhachHang = new FormChiTietKhachHang(ref formKhachHang);
            formChiTietKhachHang.ShowDialog();
        }

        private void tsbThoat_Click(object sender, EventArgs e)
        {
            this.Dispose();
        }
    }
}
